﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcShoppingMall.Model;


namespace MvcShoppingMall.Controllers
{
    /// <summary>
    /// 店铺主页面
    /// </summary>
    public class StoreController : BaseController
    {
        #region 店铺首页
        public ActionResult StoreIndex(int id = 5)
        {
            //获取店铺表信息
            var shop = dbContext.wst_shops.Find(id);
            //店铺对象
            ViewBag.shop = shop as wst_shops;

            GetGoodsByShopIdAndGoodsType(id, "特卖专区");
            GetGoodsByShopIdAndGoodsType(id, "精品推荐");
            GetGoodsByShopIdAndGoodsType(id, "热销专区");
            return View();
        }

        private void GetGoodsByShopIdAndGoodsType(int id, string goodsType)
        {
            //获取商品对象集合  
            List<wst_goods> good = (from g in dbContext.wst_goods
                                    where g.shopId == id && g.goodsTips.Contains(goodsType)
                                    select g).ToList();
            //商品对象
            ViewBag.good = good;
        }
        #endregion

        #region 店铺简介
        public ActionResult StoreAbout(int id = 5)
        {
            //获取店铺表信息
            var shop = dbContext.wst_shops.Find(id);
            //店铺对象
            ViewBag.shop = shop as wst_shops;
            //获取评分表信息
            var scores = dbContext.wst_shop_scores.Where(s => s.shopId == id).FirstOrDefault();
            //评分对象
            ViewBag.scores = scores as wst_shop_scores;
            //获取商品对象
            var good = dbContext.order_goods.Where(g => g.goodsId == id).ToList();
            //商品对象
            ViewBag.good = good;
            return View();
        }
        #endregion
    }
}
